package com.jk.smartelderlycare.controller;


import com.jk.smartelderlycare.dto.SysHomestay;
import com.jk.smartelderlycare.pojo.ResponseResult;


import com.jk.smartelderlycare.security.LoginUser;
import com.jk.smartelderlycare.service.SysHomestayServiceFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author hhk
 * @version 1.0
 * @ClassName SysHomestayController
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/11/26 16:31
 */
@Api(tags = "民宿管理")
@Slf4j
@RestController
@RequestMapping(value = "sysHomestay")
public class SysHomestayController {
    @Autowired
    private SysHomestayServiceFeign sysHomestayServiceFeign;

    /**
     * @description: 民宿信息新增
     * @param: [sysHomestay]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult
     * @author hhk
     * @date: 2024/11/25 17:18
     */
    @ApiOperation(value = "民宿信息新增",httpMethod = "POST",notes = "民宿信息新增")
    @PostMapping(value = "addSysHomestay")
    private ResponseResult addSysHomestay(@RequestBody SysHomestay sysHomestay){
        try {

            LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
            //发布人
            sysHomestay.setPublishUser(loginUser.getUser().getUsername());
            sysHomestay.setIsDelete("0");
            sysHomestay.setCreateTime(new Date());
            sysHomestayServiceFeign.addSysHomestay(sysHomestay);
            return new ResponseResult(200,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(500,"添加失败");
        }
    }

    /**
     * @description: 根据当前登陆人民宿信息列表查询
     * @param: [sysHomestay, pageNum, pageSize]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult<com.jk.smartelderlycare.pojo.PagedResponse<com.jk.smartelderlycare.dto.SysHomestay>>
     * @author hhk
     * @date: 2024/11/25 17:16
     */
    @ApiOperation(value = "根据当前登陆人民宿信息列表查询",httpMethod = "POST",notes = "根据当前登陆人民宿信息列表查询")
    @PostMapping(value = "findSysHomestayList")
    private ResponseResult<List<SysHomestay>> findSysHomestayList(@RequestBody SysHomestay sysHomestay){
        //获取当前登陆人
        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        sysHomestay.setPublishUser(loginUser.getUser().getUsername());
        return new ResponseResult<>(200,"查询成功",sysHomestayServiceFeign.findSysHomestayList(sysHomestay));
    }
    /**
     * @description: 民宿信息列表查询
     * @param: []
     * @return: com.jk.smartelderlycare.pojo.ResponseResult<java.util.List<com.jk.smartelderlycare.dto.SysHomestay>>
     * @author hhk
     * @date: 2024/11/28 16:12
     */
    @ApiOperation(value = "民宿信息列表查询",httpMethod = "GET",notes = "民宿信息列表查询")
    @GetMapping(value = "fimdSysHomestayList")
    private ResponseResult<List<SysHomestay>>fimdSysHomestayList(){
        return new ResponseResult<>(200,"查询成功",sysHomestayServiceFeign.fimdSysHomestayList());
    }
    /**
     * @description: 根据id查询民宿信息列表
     * @param: [homestayId]
     * @return: com.jk.smartelderlycare.pojo.ResponseResult<com.jk.smartelderlycare.dto.SysHomestay>
     * @author hhk
     * @date: 2024/11/28 16:45
     */
    @ApiOperation(value = "根据id查询民宿信息列表",httpMethod = "GET",notes = "根据id查询民宿信息列表")
    @GetMapping(value = "findSysHomestayById")
    private ResponseResult<SysHomestay> findSysHomestayById(@RequestParam(value = "homestayId") Long homestayId){
        return new ResponseResult<>(200,"查询成功",sysHomestayServiceFeign.findSysHomestayById(homestayId));
    }






}
